from collections import UserDict
from tkinter import messagebox
import openpyxl
import sys
from PyQt5.QtGui import QStandardItemModel
from PyQt5.QtWidgets import QApplication, QMainWindow 
import UI
import func
from functools import partial
import cx_Oracle

conn = cx_Oracle.connect('new','123456','127.0.0.1:1521')

def Driver(self):                       #司机：全部查询
    drive = []
    try:
        data = self.data
        row, col = 2 , 2 
        model = QStandardItemModel(row,col)
        cursor = conn.cursor()
        cursor.execute("select * from 司机;")
        results = cursor.fetchall()
        for i in range(row):
            drive = [str(getattr(data[i]))]
            for j in range(col):
                model.setItem(i, j, QStandardItem(drive[j]))
    except:
        messagebox.showerror(title="提示",message="查询时发生错误。")
        cursor.rollback()


def addDriver():                    #司机：添加信息
    cursor = conn.cursor()
    cursor.execute("insert into 司机 did dname")


def delDriver():                    #司机：按司机ID删除信息
    cursor = conn.cursor()
    cursor.execute("delete from 司机 where did = *输入的司机id* ")


def upDriver():                     #司机：按司机ID修改信息
    cursor = conn.cursor()
    cursor.execute("update 司机　set 列=表达式 where 条件")


def Car():                          #车辆：全部查询
    cursor = conn.cursor()
    cursor.execute("select * from 车辆;")


def Renting():                      #租赁关系：全部查询
    cursor = conn.cursor()
    cursor.execute("select * from 租赁;")


def Customer():                     #租赁客户：全部查询
    cursor = conn.cursor()
    cursor.execute("select * from 租赁客户;")


def DailyRent():                    #每日总租金
    cursor = conn.cursor()
    sqlDR = 'select sum("carrent") from 车辆;'
    cursor.execute(sqlDR)


if __name__ == '__main__':

    app = QApplication(sys.argv)
    Window = QMainWindow()
    function = func.Ui_Window()
    function.setupUi(Window)
    Window.show()

    '''func.d1.clicked.connect(Driver())
    func.d2.clicked.connect(addDriver())
    func.d3.clicked.connect(delDriver())
    func.d4.clicked.connect(upDriver())

    func.c1.clicked.connect(Car())

    func.r1.clicked.connect(Renting())

    func.u1.clicked.connect(Customer())'''


    sys.exit(app.exec_())